/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2010 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _YGIMAGEMANAGER_H_
#define _YGIMAGEMANAGER_H_

#include "YGSettings.h"
#include "YGFileManager.h"
#include "YGError.h"

namespace YoghurtGum
{

	class ImagePimpl
	{

	public:

		ImagePimpl() { }
		~ImagePimpl() { }

		bool Load(const char* a_Filename)
		{
			m_Filename = new char[strlen(a_Filename)];
			strcpy(m_Filename, a_Filename);

			char path[256];
			strcpy(path, FileManager::GetWorkingDirectory());
			strcat(path, a_Filename);

			m_Handle = fopen(path, "rb");
			if (!m_Handle)
			{
				ERROR_EXPLAIN("Could not find file '%s'.", a_Filename);
				return false;
			}

			return true;
		}

		virtual bool Parse() { return false; }

		virtual unsigned char* GetData() { return NULL; }
		uint32 GetWidth() { return m_Width; }
		uint32 GetHeight() { return m_Height; }

	protected:

		FILE* m_Handle;
		char* m_Filename;
		uint32 m_Width, m_Height;
		int32 img_n, img_out_n;
		uint8* img_buffer;
		uint8* img_buffer_end;

	}; // class ImagePimpl


	struct ImageManager
	{

		static void Init();
		static ImagePimpl* Load(const char* a_FileName);
		
	}; // class ImageManager

}; // namespace YoghurtGum

#endif